﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using BLL;
namespace ClassSystem
{
    public partial class ASPTeacherqingjiashenpi : System.Web.UI.Page
    {
        AchilveBLL bll = new AchilveBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Label1.Text = DateTime.Now.ToString();
            this.Repeater1.DataSource = bll.GetListAllY();
            this.Repeater1.DataBind();

            if (!string.IsNullOrEmpty(Request["ID"]))
            {
                int ID = Convert.ToInt32(Request["ID"]);
                AchileModel PM = bll.GetListAllY().Where(a => a.StuID == ID).FirstOrDefault();
                if (PM.LeaveApprove == 0)
                {
                    PM.LeaveApprove = 1;
                }
                
                if (bll.Updates(PM))
                {
                    Response.Redirect("ASPTeacherqingjiashenpi.aspx");
                }
                else
                {
                    Response.Write("<script>alert('修改失败！')</script>");
                }

            }

        }

        public static string FontType(string val)
        {
            if (val == "0")
            {
                return "<b style='color: red; '>未同意</b>";
            }
            else
            {
                return "<b style='color: green; '>已同意</b>";
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string TeacherName = this.TextBox1.Text.Trim();
            List<AchileModel> list = bll.GetListAllY().Where(a => a.StudentName == TeacherName).ToList();
            if (list != null)
            {
                this.Repeater1.DataSource = list;
                this.Repeater1.DataBind();
            }
            if (list.Count == 0)
            {
                Response.Write("<script>alert('查询失败！')</script>");
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            int StudentLeaveApprove = Convert.ToInt32(this.DropDownList1.SelectedValue);
            List<AchileModel> list = bll.GetListAllY().Where(a => a.LeaveApprove == StudentLeaveApprove).ToList();
            if (list != null)
            {
                this.Repeater1.DataSource = list;
                this.Repeater1.DataBind();
            }
            if (list.Count == 0)
            {
                Response.Write("<script>alert('查询失败！')</script>");
            }
        }
    }
}